package com.salesmanager.core.business.app.model;

import com.salesmanager.core.business.common.model.audit.AuditListener;
import com.salesmanager.core.business.common.model.audit.AuditSection;
import com.salesmanager.core.business.common.model.audit.Auditable;
import com.salesmanager.core.business.generic.model.SalesManagerEntity;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.io.InputStream;

/**
 * Created by Liutong on 1/12/16.
 * Android 渠道
 */
@Entity
@EntityListeners(value = AuditListener.class)
@Table(name = "ANDROID_CHANNEL",uniqueConstraints = {
        @UniqueConstraint(columnNames = {"CHANNEL_CODE"})
})
public class AndroidChannel extends SalesManagerEntity<Long,AndroidChannel> implements Auditable {

    @Id
    @Column(name = "CHANNEL_ID", unique=true, nullable=false)
    @TableGenerator(name = "TABLE_GEN", table = "SM_SEQUENCER", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
            pkColumnValue = "ANDROID_CHANNEL_NEXT_VAL",initialValue = 100000, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLE_GEN")
    private Long id;

    @Embedded
    private AuditSection auditSection = new AuditSection();

    @Column(name = "CHANNEL_CODE",columnDefinition = "VARCHAR(100) COMMENT '渠道编码'")
    private String channelCode;

    @Column(name = "CHANNEL_NAME",columnDefinition = "VARCHAR(100) COMMENT '渠道名称'")
    private String channelName;

    @Column(name = "FILE_NAME",columnDefinition = "VARCHAR(255) COMMENT '文件名称'")
    private String fileName;

    @Column(name = "FILE_SIZE",columnDefinition = "INT(11) COMMENT '文件大小'")
    private int fileSize;

    @Column(name = "FILE_MD5",columnDefinition = "VARCHAR(255) COMMENT '文件MD5'")
    private String fileMd5;

    @Column(name = "INNER_VERSION",columnDefinition = "INT(11) COMMENT '内部版本号'")
    private Integer innerVersion;

    @Column(name = "VERSION",columnDefinition = "VARCHAR(10) COMMENT '外部版本号'")
    private String version;

    @Column(name="VERSION_DESC",columnDefinition = "LONGTEXT COMMENT '版本描述'")
    @Type(type = "org.hibernate.type.StringClobType")
    private String versionDesc;

    @Column(name = "VERSION_IMAGE",columnDefinition = "VARCHAR(100) COMMENT '版本图片'")
    private String versionImage;

    @Column(name = "STATUS",columnDefinition = "INT(1) COMMENT '状态 0:无效 1:有效'")
    private Integer status = 1;

    @Column(name = "REQUIRED_UPDATE",columnDefinition = "INT(1) COMMENT '是否强制升级 0:否 1:是'")
    private Integer requiredUpdate;

    @Transient
    private InputStream apkFileInputStream; //APK文件流  用于上传文件

    @Transient
    private InputStream versionImageInputStream; //版本图片流


    @Override
    public AuditSection getAuditSection() {
        return auditSection;
    }

    @Override
    public void setAuditSection(AuditSection audit) {
        this.auditSection = audit;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }


    public String getChannelCode() {
        return channelCode;
    }

    public void setChannelCode(String channelCode) {
        this.channelCode = channelCode;
    }

    public String getChannelName() {
        return channelName;
    }

    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public int getFileSize() {
        return fileSize;
    }

    public void setFileSize(int fileSize) {
        this.fileSize = fileSize;
    }

    public String getFileMd5() {
        return fileMd5;
    }

    public void setFileMd5(String fileMd5) {
        this.fileMd5 = fileMd5;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getVersionDesc() {
        return versionDesc;
    }

    public void setVersionDesc(String versionDesc) {
        this.versionDesc = versionDesc;
    }

    public String getVersionImage() {
        return versionImage;
    }

    public void setVersionImage(String versionImage) {
        this.versionImage = versionImage;
    }

    public InputStream getApkFileInputStream() {
        return apkFileInputStream;
    }

    public void setApkFileInputStream(InputStream apkFileInputStream) {
        this.apkFileInputStream = apkFileInputStream;
    }

    public InputStream getVersionImageInputStream() {
        return versionImageInputStream;
    }

    public void setVersionImageInputStream(InputStream versionImageInputStream) {
        this.versionImageInputStream = versionImageInputStream;
    }

    public Integer getInnerVersion() {
        return innerVersion;
    }

    public void setInnerVersion(Integer innerVersion) {
        this.innerVersion = innerVersion;
    }

    public Integer getRequiredUpdate() {
        return requiredUpdate;
    }

    public void setRequiredUpdate(Integer requiredUpdate) {
        this.requiredUpdate = requiredUpdate;
    }
}
